<template>
  <div class="dashboard-container">
    <h2 class="head-big-title">Invois Pembelian</h2>
    <Pathnavigation style="margin-left: 3%;"></Pathnavigation>
    <el-form label-position="top" :model="searchData" style="width: 92%;margin: 20px 4% 0 4%;padding: 10px 2% 3px 2%;border-radius: 10px;background-color: white;text-align: left;clear: both;">
      <el-form-item label="Nombor Invois">
        <el-input v-model="searchData.invoiceId" @blur="getResetLoadData" placeholder="Nombor Invois" type="number"></el-input>
      </el-form-item>
      <el-form-item label="Nombor Pesanan">
        <el-input v-model="searchData.oid" @blur="getResetLoadData" placeholder="Nombor Pesanan" type="number"></el-input>
      </el-form-item>
      <el-form-item label="Tarikh" class="one-form-item">
        <el-date-picker
          class="input-width"
          @input="changeNew($event)"
          @change="getResetLoadData"
          v-model="searchData.date"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="Tarikh">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <div style="width: 96%;margin: 20px 2% 0 2%;padding-left: 10px;border-radius: 20px;background-color: rgb(245,246,247);text-align: left;">
      <div v-for="(item,index) in tableData" :key="index" style="width: 100%;border-radius: 10px;background-color: white;padding: 6px 5px 15px 6px;margin-bottom: 10px;">
        <strong>Nombor Invois {{item.invoiceId}}</strong>
        <svg-icon icon-class="ico_view" style="font-size: 24px;float: right;margin-right: 5%;position: relative;bottom: 3px;" @click="handleEdit(item)"></svg-icon>
        <div style="width: 10px;height: 2px;"></div>
        <el-divider></el-divider>
        <div style="width: 100%;line-height: 24px;">
          <strong style="display: block;">PO Number #{{item.oid}}</strong>
          <strong style="display: block;">{{item.buyerName}}</strong>
        </div>
        <div style="width: 100%;line-height: 28px;">
          <div style="width: 50%;display: inline-block;">
            <strong>Tarikh</strong>
            <p>{{$getTime(item.date)}}</p>
          </div>
          <div style="width: 49%;display: inline-block;">
            <strong>Jumlah</strong>
            <p>{{$formatMoneyStr(item.subFee)}}</p>
          </div>
        </div>
      </div>
    </div>
    <el-pagination
      style="float: right;margin: 12px 0 12px;"
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :page-size="searchData.pageNum"
      :current-page="searchData.pageIndex"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { order_invoice_queryApi, query_masterDealerApi } from '@/api/user'

export default {
  name: 'Customers',
  computed: {
    ...mapGetters([
      'name',
      'role'
    ])
  },
  data() {
    return {
      tableData: [],
      dealerList: [],
      searchData: {
        pageNum: 10,
        pageIndex: 1
      },
      payData: {
        UserName: 10,
        ProdDesc: 1
      },
      orderChart: ''
    }
  },
  created() {
    this.$removeDetail()
    this.getDealerList()
    this.loadData()
  },
  mounted() {
  },
  methods: {
    getResetLoadData() {
      this.searchData.pageIndex = 1
      this.loadData()
    },
    getDealerList() {
      if (this.role === this.adminValue) {
        query_masterDealerApi({ pageNum: 100, pageIndex: 1 }).then(res => {
          this.dealerList = res.data
        }).catch(err => {
          this.dealerList = []
          console.log(err)
        })
      }
      this.dealerList = []
    },
    loadData() {
      order_invoice_queryApi(this.searchData).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
      }).catch(err => {
        console.log(err)
      })
    }, // 得到数据表格
    handleEdit(row) {
      this.$router.push('/Invoices/Detail/' + row.oid)
    },
    handleCurrentChange(val) {
      console.log('Chose ', val)
      this.loadData()
    }
  }
}
</script>

<style lang="scss" scoped>
  .head-big-title{
    text-align: left;
    font-size: 20px;
    margin: 20px 0 0 3%;
  }
  .dashboard-container{
    margin-top: 20px;
    text-align: center;
  }
  .one-form-item{
    display: block;
    .el-select{
      width: 100%;
    }
    .el-input{
      width: 100%;
    }
  }
</style>
<style scoped>
  /deep/.head-search label{
    line-height: 30px;
  }

  /deep/ .el-divider {
    margin: 8px 0 10px 0;
  }
</style>
